package com.study.demo;

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.EventDispatcher;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Cursor;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundImage;
import javafx.scene.layout.BackgroundPosition;
import javafx.scene.layout.BackgroundRepeat;
import javafx.scene.layout.BackgroundSize;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

public class QQLogMain extends Application{

	ImageView imageViewRadioButtonRem;
	boolean Remember = false;
	ImageView imageViewRadioButtonAuto;
	boolean Auto = false;
	ImageView imageViewBk;
	Stage select;
	int condition = 2;

	ImageView imageViewClose = new ImageView();
	ImageView imageViewMini = new ImageView();

	public static void main(String[] args) {
		launch(args);

	}

	/* (non-Javadoc)
	 * @see javafx.application.Application#start(javafx.stage.Stage)
	 */
	@Override
	public void start(Stage primaryStage) throws Exception {

		GridPane gridPane = new GridPane();
		StackPane TopPane = new StackPane();

		Text textID = new Text("输入QQ账号");
		textID.setFill(Color.GRAY);
		Text textPass = new Text("输入QQ密码");
		textPass.setFill(Color.GRAY);

		TextField textFieldID = new TextField();
		textFieldID.setText(textID.getText());
		PasswordField passwordField = new PasswordField();
		passwordField.setText(textPass.getText());


		Image imageTop = new Image("file:image\\res\\LoginFrame\\bk.jpg");
		Image imageQQLog = new Image("file:image\\res\\LoginFrame\\logo-banner.png");
		Image imageCloseNormal = new Image("file:image\\res\\SysBtn\\sysbtn_close_normal.png");
		Image imageCloseHighLight = new Image("file:image\\res\\SysBtn\\sysbtn_close_hover.png");
		Image imageCloseDown = new Image("file:image\\res\\SysBtn\\sysbtn_close_down.png");

		Image imageMiniNormal = new Image("file:image\\res\\SysBtn\\sysbtn_min_normal.png");
		Image imageMiniHighLight = new Image("file:image\\res\\SysBtn\\sysbtn_min_hover.png");
		Image imageMiniDown = new Image("file:image\\res\\SysBtn\\sysbtn_min_down.png");


		imageViewClose.setImage(imageCloseNormal);
		imageViewMini.setImage(imageMiniNormal);

//		Button btMini = new Button();
//		Button btClose = new Button();
//		btClose.setBackground(new Background(new BackgroundImage(imageCloseNormal,
//				BackgroundRepeat.NO_REPEAT,
//				BackgroundRepeat.NO_REPEAT,
//				BackgroundPosition.DEFAULT,
//				BackgroundSize.DEFAULT)
//				));
//		btMini.setBackground(new Background(new BackgroundImage(imageMiniNormal,
//				BackgroundRepeat.NO_REPEAT,
//				BackgroundRepeat.NO_REPEAT,
//				BackgroundPosition.DEFAULT,
//				BackgroundSize.DEFAULT)
//				));
		imageViewClose.setFitWidth(30);
		imageViewClose.setFitHeight(30);
		imageViewMini.setFitWidth(30);
		imageViewMini.setFitHeight(30);

		ImageView imageViewTop = new ImageView(imageTop);
		ImageView imageViewQQLog = new ImageView(imageQQLog);

		//登录状态
		Image imageAway = new Image("file:image\\res\\LoginFrame\\status\\away.png");
		Image imageBusy = new Image("file:image\\res\\LoginFrame\\status\\busy.png");
		Image imageImonline = new Image("file:image\\res\\LoginFrame\\status\\imonline.png");//在线
		Image imageInvisible = new Image("file:image\\res\\LoginFrame\\status\\invisible.png");//隐身
		Image imageMute = new Image("file:image\\res\\LoginFrame\\status\\mute.png");
		Image imageQme = new Image("file:image\\res\\LoginFrame\\status\\Qme.png");
		Image imageBk = new Image("file:image\\res\\LoginFrame\\status\\bk.png");

		ImageView imageViewAway = new ImageView(imageAway);
		ImageView imageViewBusy = new ImageView(imageBusy);
		ImageView imageViewImonline = new ImageView(imageImonline);
		ImageView imageViewInvisible = new ImageView(imageInvisible);
		ImageView imageViewMute = new ImageView(imageMute);
		ImageView imageViewQme = new ImageView(imageQme);
		imageViewBk = new ImageView();
		ImageView imageViewCondition = new ImageView();//默认在线状态
		imageViewCondition.setImage(imageImonline);

		ImageView imageViewAwayBk = new ImageView();
		Pane imageAwayPane = new Pane();imageAwayPane.getChildren().addAll(imageViewAwayBk,imageViewAway);
		//选择
		imageAwayPane.addEventHandler(MouseEvent.MOUSE_CLICKED, (MouseEvent e) -> {
			imageViewAwayBk.setImage(imageBk);
			imageViewCondition.setImage(imageAway);
			select.close();
		});
		//悬停
		imageAwayPane.addEventHandler(MouseEvent.MOUSE_ENTERED, (MouseEvent e) -> {
			imageViewAwayBk.setImage(imageBk);

		});
		//离开
		imageAwayPane.addEventHandler(MouseEvent.MOUSE_EXITED, (MouseEvent e) -> {
			imageViewAwayBk.setImage(null);
		});


		ImageView imageViewBusyBk = new ImageView();
		Pane imageBusyPane = new Pane();imageBusyPane.getChildren().addAll(imageViewBusyBk,imageViewBusy);
		//选择
		imageBusyPane.addEventHandler(MouseEvent.MOUSE_CLICKED, (MouseEvent e) -> {
			imageViewBusyBk.setImage(imageBk);
			imageViewCondition.setImage(imageBusy);
			select.close();
		});
		//悬停
		imageBusyPane.addEventHandler(MouseEvent.MOUSE_ENTERED, (MouseEvent e) -> {
			imageViewBusyBk.setImage(imageBk);

		});
		//离开
		imageBusyPane.addEventHandler(MouseEvent.MOUSE_EXITED, (MouseEvent e) -> {
			imageViewBusyBk.setImage(null);
		});


		ImageView imageViewImonlineBk = new ImageView();
		Pane imageImonlinePane = new Pane();imageImonlinePane.getChildren().addAll(imageViewImonlineBk,imageViewImonline);
		//选择
		imageImonlinePane.addEventHandler(MouseEvent.MOUSE_CLICKED, (MouseEvent e) -> {
			imageViewImonlineBk.setImage(imageBk);
			imageViewCondition.setImage(imageImonline);
			select.close();
		});
		//悬停
		imageImonlinePane.addEventHandler(MouseEvent.MOUSE_ENTERED, (MouseEvent e) -> {
			imageViewImonlineBk.setImage(imageBk);

		});
		//离开
		imageImonlinePane.addEventHandler(MouseEvent.MOUSE_EXITED, (MouseEvent e) -> {
			imageViewImonlineBk.setImage(null);
		});


		ImageView imageViewInvisibleBk = new ImageView();
		Pane imageInvisiblePane = new Pane();imageInvisiblePane.getChildren().addAll(imageViewInvisibleBk,imageViewInvisible);
		//选择
		imageInvisiblePane.addEventHandler(MouseEvent.MOUSE_CLICKED, (MouseEvent e) -> {
			imageViewInvisibleBk.setImage(imageBk);
			imageViewCondition.setImage(imageInvisible);
			select.close();
		});
		//悬停
		imageInvisiblePane.addEventHandler(MouseEvent.MOUSE_ENTERED, (MouseEvent e) -> {
			imageViewInvisibleBk.setImage(imageBk);

		});
		//离开
		imageInvisiblePane.addEventHandler(MouseEvent.MOUSE_EXITED, (MouseEvent e) -> {
			imageViewInvisibleBk.setImage(null);
		});


		ImageView imageViewMuteBk = new ImageView();
		Pane imageMutePane = new Pane();imageMutePane.getChildren().addAll(imageViewMuteBk,imageViewMute);
		//选择
		imageMutePane.addEventHandler(MouseEvent.MOUSE_CLICKED, (MouseEvent e) -> {
			imageViewMuteBk.setImage(imageBk);
			imageViewCondition.setImage(imageMute);
			select.close();
		});
		//悬停
		imageMutePane.addEventHandler(MouseEvent.MOUSE_ENTERED, (MouseEvent e) -> {
			imageViewMuteBk.setImage(imageBk);

		});
		//离开
		imageMutePane.addEventHandler(MouseEvent.MOUSE_EXITED, (MouseEvent e) -> {
			imageViewMuteBk.setImage(null);
		});


		ImageView imageViewQmeBk = new ImageView();
		Pane imageQmePane = new Pane();imageQmePane.getChildren().addAll(imageViewQmeBk,imageViewQme);
		//选择
		imageQmePane.addEventHandler(MouseEvent.MOUSE_CLICKED, (MouseEvent e) -> {
			imageViewQmeBk.setImage(imageBk);
			imageViewCondition.setImage(imageQme);
			select.close();
		});
		//悬停
		imageQmePane.addEventHandler(MouseEvent.MOUSE_ENTERED, (MouseEvent e) -> {
			imageViewQmeBk.setImage(imageBk);

		});
		//离开
		imageQmePane.addEventHandler(MouseEvent.MOUSE_EXITED, (MouseEvent e) -> {
			imageViewQmeBk.setImage(null);
		});

		//下拉状态栏
		VBox vboxCondition = new VBox();
		vboxCondition.getChildren().addAll(imageImonlinePane,imageAwayPane,imageBusyPane,imageInvisiblePane,imageMutePane,imageQmePane);

		//状态面板
		Pane conditionPane = new Pane();
		conditionPane.getChildren().addAll(imageViewBk,imageViewCondition);

		select = new Stage();
		select.initStyle(StageStyle.TRANSPARENT);
		Scene SelectScene = new Scene(vboxCondition);
		select.setScene(SelectScene);

		vboxCondition.addEventHandler(MouseEvent.MOUSE_EXITED, (MouseEvent e) -> {
			select.close();
		});

		//选择
		conditionPane.addEventHandler(MouseEvent.MOUSE_CLICKED, (MouseEvent e) -> {
			imageViewBk.setImage(imageBk);
			select.show();

		});
		//悬停
		conditionPane.addEventHandler(MouseEvent.MOUSE_ENTERED, (MouseEvent e) -> {
			imageViewBk.setImage(imageBk);
		});
		//离开
		conditionPane.addEventHandler(MouseEvent.MOUSE_EXITED, (MouseEvent e) -> {
			imageViewBk.setImage(null);
		});

		//头像
		Image imagehead = new Image("file:image\\res\\timg.jpg");
		ImageView imageViewHead = new ImageView(imagehead);
		imageViewHead.setFitWidth(90);
		imageViewHead.setFitHeight(90);
		Pane headPane = new Pane();
		headPane.getChildren().addAll(imageViewHead,conditionPane);
		conditionPane.setLayoutX(75);
		conditionPane.setLayoutY(75);
		select.setX(660);
		select.setY(450);


		TopPane.getChildren().addAll(imageViewTop,imageViewQQLog);

		VBox mainVbox = new VBox();
		HBox hbox = new HBox();
		VBox vboxInput = new VBox();
		VBox vboxLink = new VBox();
		Pane RadioButtonPane  = new Pane();
		Pane btPane = new Pane();
		btPane.getChildren().addAll(TopPane,imageViewClose,imageViewMini);
		imageViewClose.setLayoutX(400);
		imageViewClose.setLayoutY(0);
		imageViewMini.setLayoutX(370);
		imageViewMini.setLayoutY(0);

		gridPane.add(btPane, 0,0);//，node,列，行
		gridPane.add(hbox, 0,1);

		Hyperlink linkRegister = new Hyperlink("注册账号");
		Hyperlink linkLostPass = new Hyperlink("找回密码");

		Image imageRadioButtonNormal = new Image("file:image\\res\\LoginFrame\\CheckBox\\CheckBox_normal.png");
		Image imageRadioButtonHover = new Image("file:image\\res\\LoginFrame\\CheckBox\\CheckBox_down.png");
		Image imageRadioButtonTickNormal = new Image("file:image\\res\\LoginFrame\\CheckBox\\Checkbox_tick_normal.png");
		Image imageRadioButtonTickHover = new Image("file:image\\res\\LoginFrame\\CheckBox\\Checkbox_tick_highlight.png");
		imageViewRadioButtonRem = new ImageView(imageRadioButtonNormal);
		imageViewRadioButtonAuto = new ImageView(imageRadioButtonNormal);

		Label LabelRemember = new Label("记住密码");
		Label LabelAuto = new Label("自动登录");
		//Auto
		//选择
		imageViewRadioButtonAuto.addEventHandler(MouseEvent.MOUSE_CLICKED, (MouseEvent e) -> {
			if(Auto)//已选择
			{
				Auto = false;
				imageViewRadioButtonAuto.setImage(imageRadioButtonNormal);
			}
			else//未选择
			{
				Auto = true;
				imageViewRadioButtonAuto.setImage(imageRadioButtonTickNormal);
			}
		});
		//悬停
		imageViewRadioButtonAuto.addEventHandler(MouseEvent.MOUSE_ENTERED, (MouseEvent e) -> {
			if(Auto)//已选择
				imageViewRadioButtonAuto.setImage(imageRadioButtonTickHover);
			else//未选择
				imageViewRadioButtonAuto.setImage(imageRadioButtonHover);
		});
		//离开
		imageViewRadioButtonAuto.addEventHandler(MouseEvent.MOUSE_EXITED, (MouseEvent e) -> {
			if(Auto)//已选择
				imageViewRadioButtonAuto.setImage(imageRadioButtonTickNormal);
			else//未选择
				imageViewRadioButtonAuto.setImage(imageRadioButtonNormal);
		});

		//选择
		LabelAuto.addEventHandler(MouseEvent.MOUSE_CLICKED, (MouseEvent e) -> {
			if(Auto)//已选择
			{
				Auto = false;
				imageViewRadioButtonAuto.setImage(imageRadioButtonNormal);
			}
			else//未选择
			{
				Auto = true;
				imageViewRadioButtonAuto.setImage(imageRadioButtonTickNormal);
			}
		});
		//悬停
		LabelAuto.addEventHandler(MouseEvent.MOUSE_ENTERED, (MouseEvent e) -> {
			if(Auto)//已选择
				imageViewRadioButtonAuto.setImage(imageRadioButtonTickHover);
			else//未选择
				imageViewRadioButtonAuto.setImage(imageRadioButtonHover);
		});
		//离开
		LabelAuto.addEventHandler(MouseEvent.MOUSE_EXITED, (MouseEvent e) -> {
			if(Auto)//已选择
				imageViewRadioButtonAuto.setImage(imageRadioButtonTickNormal);
			else//未选择
				imageViewRadioButtonAuto.setImage(imageRadioButtonNormal);
		});

		//remember
		//选择
		imageViewRadioButtonRem.addEventHandler(MouseEvent.MOUSE_CLICKED, (MouseEvent e) -> {
			if(Remember)//已选择
			{
				Remember = false;
				imageViewRadioButtonRem.setImage(imageRadioButtonNormal);
			}
			else//未选择
			{
				Remember = true;
				imageViewRadioButtonRem.setImage(imageRadioButtonTickNormal);
			}
		});
		//悬停
		imageViewRadioButtonRem.addEventHandler(MouseEvent.MOUSE_ENTERED, (MouseEvent e) -> {
			if(Remember)//已选择
				imageViewRadioButtonRem.setImage(imageRadioButtonTickHover);
			else//未选择
				imageViewRadioButtonRem.setImage(imageRadioButtonHover);
		});
		//离开
		imageViewRadioButtonRem.addEventHandler(MouseEvent.MOUSE_EXITED, (MouseEvent e) -> {
			if(Remember)//已选择
				imageViewRadioButtonRem.setImage(imageRadioButtonTickNormal);
			else//未选择
				imageViewRadioButtonRem.setImage(imageRadioButtonNormal);
		});
		//选择

		LabelRemember.addEventHandler(MouseEvent.MOUSE_CLICKED, (MouseEvent e) -> {
			if(Remember)//已选择
			{
				Remember = false;
				imageViewRadioButtonRem.setImage(imageRadioButtonNormal);
			}
			else//未选择
			{
				Remember = true;
				imageViewRadioButtonRem.setImage(imageRadioButtonTickNormal);
			}
		});
		//悬停
		LabelRemember.addEventHandler(MouseEvent.MOUSE_ENTERED, (MouseEvent e) -> {
			if(Remember)//已选择
				imageViewRadioButtonRem.setImage(imageRadioButtonTickHover);
			else//未选择
				imageViewRadioButtonRem.setImage(imageRadioButtonHover);
		});
		//离开
		LabelRemember.addEventHandler(MouseEvent.MOUSE_EXITED, (MouseEvent e) -> {
			if(Remember)//已选择
				imageViewRadioButtonRem.setImage(imageRadioButtonTickNormal);
			else//未选择
				imageViewRadioButtonRem.setImage(imageRadioButtonNormal);
		});
//		Image imageCloseNormal = new Image("file:image\\res\\SysBtn\\sysbtn_close_normal.png");
//		Image imageCloseHighLight = new Image("file:image\\res\\SysBtn\\sysbtn_close_hover.png");
//		Image imageCloseDown = new Image("file:image\\res\\SysBtn\\sysbtn_close_down.png");
//
//		Image imageMiniNormal = new Image("file:image\\res\\SysBtn\\sysbtn_min_normal.png");
//		Image imageMiniHighLight = new Image("file:image\\res\\SysBtn\\sysbtn_min_hover.png");
//		Image imageMiniDown = new Image("file:image\\res\\SysBtn\\sysbtn_min_down.png");
		//关闭按钮
		//悬停
		imageViewMini.addEventHandler(MouseEvent.MOUSE_ENTERED, (MouseEvent e) -> {
			imageViewMini.setImage(imageMiniHighLight);
		});
		//离开
		imageViewMini.addEventHandler(MouseEvent.MOUSE_EXITED, (MouseEvent e) -> {
			imageViewMini.setImage(imageMiniNormal);
		});
		imageViewMini.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
			@Override
			public void handle(MouseEvent event) {
				primaryStage.setIconified(true);
			}
		});
		imageViewClose.addEventHandler(MouseEvent.MOUSE_ENTERED, (MouseEvent e) -> {
			imageViewClose.setImage(imageCloseHighLight);
		});
		//离开
		imageViewClose.addEventHandler(MouseEvent.MOUSE_EXITED, (MouseEvent e) -> {
			imageViewClose.setImage(imageCloseNormal);
		});
		//单击
		imageViewClose.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() {
			@Override
			public void handle(MouseEvent event) {
				primaryStage.close();
			}
		});

		Pane paneLog = new Pane();
		Image imageLogNornal = new Image("file:image\\res\\LoginFrame\\button_login_normal.png");
		Image imageLogHover = new Image("file:image\\res\\LoginFrame\\button_login_hover.png");

		//登录按钮
		Text textLog = new Text("登录");
		textLog.setFill(Color.WHITE);
		Button btLog = new Button();
		btLog.setPrefSize(200, 30);


		btLog.setBackground(new Background(new BackgroundImage(imageLogNornal,
				BackgroundRepeat.NO_REPEAT,
				BackgroundRepeat.NO_REPEAT,
				BackgroundPosition.DEFAULT,
				BackgroundSize.DEFAULT)
				));
		btLog.addEventHandler(MouseEvent.MOUSE_ENTERED, (MouseEvent e) -> {
			btLog.setBackground(new Background(new BackgroundImage(imageLogHover,
					BackgroundRepeat.NO_REPEAT,
					BackgroundRepeat.NO_REPEAT,
					BackgroundPosition.DEFAULT,
					BackgroundSize.DEFAULT)
					));
		});
		btLog.addEventHandler(MouseEvent.MOUSE_EXITED, (MouseEvent e) -> {
			btLog.setBackground(new Background(new BackgroundImage(imageLogNornal,
					BackgroundRepeat.NO_REPEAT,
					BackgroundRepeat.NO_REPEAT,
					BackgroundPosition.DEFAULT,
					BackgroundSize.DEFAULT)
					));
		});
		btLog.setOnAction(e->{
			/*Check checkIDPsw = new Check(textFieldID.getText(),passwordField.getText());
			checkIDPsw.check();*/
		});


		paneLog.getChildren().addAll(btLog,textLog);
		textLog.setX(220);
		textLog.setY(30);
		btLog.setLayoutX(140);
		btLog.setLayoutY(10);

		RadioButtonPane.getChildren().addAll(imageViewRadioButtonRem,LabelRemember,imageViewRadioButtonAuto,LabelAuto);
		imageViewRadioButtonRem.setLayoutX(5);
		imageViewRadioButtonRem.setLayoutY(5);
		LabelRemember.setLayoutX(20);
		LabelRemember.setLayoutY(6);
		imageViewRadioButtonAuto.setLayoutX(130);
		imageViewRadioButtonAuto.setLayoutY(5);
		LabelAuto.setLayoutX(145);
		LabelAuto.setLayoutY(6);

		hbox.getChildren().addAll(headPane,vboxInput,vboxLink);
		vboxInput.getChildren().addAll(textFieldID,passwordField,RadioButtonPane);
		linkRegister.setPadding(new Insets(10,10,15,5));
		linkLostPass.setPadding(new Insets(0,10,15,5));
		vboxLink.getChildren().addAll(linkRegister,linkLostPass);
		hbox.setPadding(new Insets(15,20,0,30));
		vboxInput.setPadding(new Insets(3,10,0,20));

		mainVbox.getChildren().addAll(gridPane,paneLog);

		textFieldID.setPrefSize(200, 30);


		passwordField.setPrefSize(200, 30);



		Pane mainPane = new Pane();
		mainPane.getChildren().addAll(mainVbox);
		Scene scene = new Scene(mainPane);
		Stage stage = new Stage();
//		stag
		primaryStage.setTitle("QQ登录界面");
		primaryStage.setWidth(429);
		primaryStage.setHeight(350);
		primaryStage.setScene(scene);
		primaryStage.initStyle(StageStyle.TRANSPARENT);
		primaryStage.show();



	}

}
